package com.changgou.system.service.impl;

import cn.hutool.crypto.digest.BCrypt;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changgou.system.dao.AdminMapper;
import com.changgou.system.pojo.Admin;
import com.changgou.system.service.AdminService;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Override
    public boolean login(Admin admin) {
        //根据登录名查询管理员
        Admin admin1 = new Admin();
        admin1.setLoginName(admin.getLoginName());
        admin1.setStatus("1");
        Admin admin2 = super.getById(admin1);//数据库查询出的对象
        if (admin2 == null) {
            return false;
        } else {
            //验证密码, Bcrypt为spring的包, 第一个参数为明文密码, 第二个参数为密文密码
            return BCrypt.checkpw(admin.getPassword(), admin2.getPassword());
        }
    }



//    /**
//     * 增加
//     * @param admin
//     */
//    @Override
//    public void add(Admin admin){
//        String password = BCrypt.hashpw(admin.getPassword(), BCrypt.gensalt());
//        admin.setPassword(password);
//        adminMapper.insert(admin);
//    }


}
